#ifndef EDGE_H
#define EDGE_H

#include "..\Node\Node.h"
#include "..\LinkedListGeneralDefinition\LinkedListGeneralDefinition.h"
#include "..\Owner\Owner.h"

#define DOWNLOAD	0
#define	UPLOAD		1
#define MAXTIME		99999

struct EDGE {
	nodeAddress A;
	nodeAddress B;
	float uploadSpeed;
	float downloadSpeed;
	
	struct EDGE *next;
} Edge;

typedef struct EDGE edge;
typedef edge* edgeAddress;

typedef edgeAddress edgeList;

// SELEKTORs
#define GetA(E) 		(E)->A
#define GetB(E) 		(E)->B
#define GetUpload(E) 	(E)->uploadSpeed
#define GetDownload(E) 	(E)->downloadSpeed

// KONSTRUKTOR - DESTRUKTOR
edgeList	CreateEmptyEdgeList();
edgeAddress	AllocateEdge(nodeAddress A, nodeAddress B, float uploadSpeed, float downloadSpeed);
edgeAddress	AllocateEdgeAdv(nodeAddress A, nodeAddress B, float uploadSpeed, float downloadSpeed, edgeAddress next);
void		DeallocateEdge(edge *e);

// OPERASI
edgeAddress SearchEdgeByNode(edgeList *EL, nodeAddress node);
edgeAddress SearchEdgeByNodes(edgeList *EL, nodeAddress A, nodeAddress B);

bool		SearchEdge(edgeList *EL, edgeAddress E);

void		DestroyEdge(edgeList *EL, edgeAddress E);

void		DestroyEdgeList(edgeList *EL);

void		AddEdge(edgeList *EL, edgeAddress e);
/**********************************************************************************
	Menambahkan e ke EL
	I.S. : 	e sudah dialokasi
	F.S. : 	EL berisi e terurut berdasarkan nama node A, nama node B, downloadspeed, uploadspeed
**********************************************************************************/ 

// OPERASI TERKAIT GRAPH
void GraphShortestPath(int size, int type, edgeList Graph, nodeAddress from, nodeAddress to, float *out_time, char *out_shortestpath);
/**********************************************************************************
	Mencari jalur terpendek dari from ke to dalam Graph
	type = DOWNLOAD atau UPLOAD
	I.S. : 	from dan to ada di dalam Graph
	F.S. : 	out_time berisi waktu yang diperlukan untuk mentransfer data sebesar size
			out_shortestpath berisi jalur yang dilalui dengan format : from - .. - .. - .. - to
**********************************************************************************/ 

// fungsi di bawah adalah fungsi bantuan

void GraphShortestPathRecursive(int size, int type, edgeList Graph, nodeAddress from, nodeAddress to, float *out_time, char *out_shortestpath, float temp_time, char *temp_path_get, ownerList Own);
// Rekursif untuk GraphShortestPath

int EdgeLess(edgeAddress E, edgeAddress e);
// mengecek apakah E < e
// jika !EdgeLess, berarti ngecek E >= e

void PrintEdge(edgeAddress E);
// Print nama SIte-A, Site-B dan nilai DOwnloadSPeed dan UploadSpeed

void PrintEdgeHeader();
// Print Header buat edge (Site-A Site-B DownloadSpeed UploadSpeed


#endif
